package com.adcc.automation.service.configuration;

import lombok.Data;

import java.util.Map;

@Data
public class MQProperties {
    // URL
    private String url;
    
    // 用户名
    private String user;
    
    // 密码
    private String password;
    
    // 接收队列
    private String fplQueue;
    
    // 接收队列
    private String recvCommandQueue;
    
    // 发送指令队列
    private String sendCommandQueue;
    
    private String recvTopic;
    
    private String sendTopic;
    
    // 发送TTL阀值
    private int ttl;
    
    // 最大连接数
    private int maxConnections;
    
    // 最大活跃连接数
    private int maxActiveConnections;
    
    // 连接空闲时间
    private int idleTimeout;
    
    // 连接过期时间
    private int expiryTimeout;
    
    // ACK模式（0：Transfer，1：Auto）
    private int ackMode;
    
    // 消息是否使用Text方式传输（false：byte方式；true：text方式）
    private boolean textTransfer;
    
    //心跳发送频率
    private int hbSendInterval;
    
    public MQProperties(Map<String,Object> map) throws Exception{
        this.ttl = 30000;
        this.maxConnections = 30;
        this.maxActiveConnections = 10;
        this.idleTimeout = 30000;
        this.expiryTimeout = 300000;
        this.ackMode = 1;
        this.textTransfer = false;
        try {
            if (map != null) {
                for (Map.Entry<String,Object> entry : map.entrySet()) {
                    if (entry.getValue() != null) {
                        switch (entry.getKey()) {
                            case "url" -> this.url = entry.getValue().toString();
                            case "user" -> this.user = entry.getValue().toString();
                            case "password" -> this.password = entry.getValue().toString();
                            case "fplQueue" -> this.fplQueue = entry.getValue().toString();
                            case "recvCommandQueue" -> this.recvCommandQueue = entry.getValue().toString();
                            case "sendCommandQueue" -> this.sendCommandQueue = entry.getValue().toString();
                            case "recvTopic" -> this.recvTopic = entry.getValue().toString();
                            case "sendTopic" -> this.sendTopic = entry.getValue().toString();
                        }
                    }
                }
            }
        }catch (Exception e) {
            throw new Exception("MQProperties init error",e);
        }
    }
}
